﻿using System.IO;
using UnityEngine;

namespace SimpleCore
{
    public class FileTool
    {
        public static string Read(string path)
        {
            if (!File.Exists(path))
            {
                Debug.LogError($"Dont Find {path}");
                return "";
            }

            string content;
            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    content = sr.ReadToEnd();
                    sr.Dispose();
                }
                fs.Dispose();
            }

            return content;
        }

        public static void Write(string path, string content)
        {
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(content);
                
                    sw.Dispose();
                }
            
                fs.Dispose();
            }
        }
    
    }
}